
<template>
  <div>
    <el-form :inline="true" :label-position="'right'"  class="demo-form-inline">

      <el-form-item label="是否延期起租">
        <el-select v-model="selectedIsorNo"  @change="changIsorNo">
          <el-option
              v-for="item in baseOptions"
              :key="item.value"
              :label="item.attr_value_name"
              :value="item.attr_value"
            ></el-option>
        </el-select>
      </el-form-item>
      <br/>
      <el-form-item label="延期起租原因">
        <el-select v-model="selected"  :disabled="selectDis" @change="changeReson">
          <el-option
              v-for="item in baseOptions2"
              :key="item.value"
              :label="item.attr_value_name"
              :value="item.attr_value"
            ></el-option>
        </el-select>
      </el-form-item>
      <br/>
      <el-form-item label="关联ICT流水号">
        <el-input v-model="inputs" :disabled="inputDis"></el-input>
      </el-form-item>   
      
    </el-form>

    <template >
      <div class="subDiv">
        <el-button type="success" @click="submit()">确定</el-button>
        <el-button type="danger" @click="closeDialog()">取消</el-button>
      </div>
    </template>

     
  </div>
</template>

<script>
import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
import OrderService from "@/api/order/OrderService";

export default {
  components: {
    requestUtil,
		CustOrderService,
    OrderService
  },
  async mounted(){     
    console.log(this.CTOInfo);
    let params = {
				interFaceType: "ORDER",
				sqlId: 2021082701,
				paramStr: "attrId:"+100011523,
			};
    const resultSel =await OrderService.getCustNum(params);
    
    if(resultSel.code == 200 && resultSel.meta.resCode==0){
      this.baseOptions=resultSel.meta.resList.executeSqlResps;
    }

    let params2 = {
        interFaceType: "ORDER",
        sqlId: 2021082701,
        paramStr: "attrId:"+100012601,
      };
    const resultSel2 =await OrderService.getCustNum(params2);
    
    if(resultSel2.code == 200 && resultSel2.meta.resCode==0){
      this.baseOptions2=resultSel2.meta.resList.executeSqlResps;
    }

  },

  props:{
	  	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
		CTOInfo: {
			type: Array,
			default: () => {
				return [];
			},
		},

  },
  data() {
    return {
      selectedIsorNo:[],
      selected:[],
      inputs:"",
      baseOptions: [],
      baseOptions2: [],
      selectDis : true,
      inputDis: true,
	  }
  },
  methods: {
    // 上传
    async submit(param){
      if(this.selectedIsorNo==""){
        this.$alert("请选择是否延期起租!", "警告", {
          type: "warning",
          confirmButtonText: "关闭",
        });
        return false;
      }
      if(this.selectedIsorNo=="1" && this.selected=="" ){
        this.$alert("请选择延期起租原因!", "警告", {
          type: "warning",
          confirmButtonText: "关闭",
        });
        return false;
      }
      if(this.inputs=="" && this.selected=="31750001" ){
        this.$alert("请录入关联ICT流水号!", "警告", {
          type: "warning",
          confirmButtonText: "关闭",
        });
        return false;
      }
      var orderItemIds="";      
      for (var i = 0; i < this.CTOInfo.length; i++) {
        orderItemIds +=","+this.CTOInfo[i].orderItemId;
      }
      var isDelayRent = this.selectedIsorNo;
      var delayRentReason = this.selected;
      var ictOrderNbr = this.inputs;
      var custId = this.CTOInfo[0].custId;
      const results =await OrderService.orderDelayRent({orderItemIds,isDelayRent,delayRentReason,ictOrderNbr,custId});
      console.log(results); 
      if(results.code=="0"){
          this.$confirm("保存成功", "提示", {  
            confirmButtonText: "确定",
            showCancelButton: false,
            type: "warn",
            center: true
          });
          this.$emit('update:show',false);
      }else{
        this.$confirm("保存失败"+results.meta, "提示", {  
            confirmButtonText: "确定",
            showCancelButton: false,
            type: "warn",
            center: true
          });
      }
    

    },
    // 关闭
    closeDialog(){
      this.$emit('update:show',false);

    },
    // 是否起租选择后触发事件
    async changIsorNo(value){
        if(value == "1"){
          this.selectDis = false;
        }else{
          this.selected='';
          this.inputs="";
          this.selectDis = true;     
          this.inputDis = true;
        }
    },

    changeReson(value){
        if(value == "31750001"){          
          this.inputDis =  false;
        }else{
          this.inputDis = true;
          this.inputs="";
        }
    }
  }
}
</script>
<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
.el-table--enable-row-transition{
  margin-bottom: 20px;
}
.subDiv{
 text-align: center;
}
</style>

